#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const int N=2e5+10;
#define INF 0x3f3f3f3f;
typedef long long int ll;
#define close(); std::ios::sync_with_stdio(false);cin.tie(0),cout.tie(0);
//----------------------------------------------------------------------------//
ll a[1010],n;
ll head[1010],ass[1010];
void solve()
{
	cin>>n;
	ll tmp=0;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(i==1) head[i]=0;
		else head[i]=tmp;
		tmp=max(tmp,a[i]);
	}

	tmp=0;
	for(int i=n;i>=1;i--)
	{
		if(i==n) ass[i]=tmp;
		else ass[i]=tmp;
		tmp=max(tmp,a[i]);
	}

	ll mx=-INF;
	for(int i=1;i<=n;i++)
	{
		mx=max(mx,a[i]+head[i]);
		mx=max(mx,a[i]+ass[i]);
	}

	cout<<mx<<'\n';

	
}

int main()
{
	close();
	int T; cin>>T;
	while (T--) solve();
	return 0;
}